<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/jquery.js"></script>
    <script src="./lib/template-web.js"></script>
</head>

<body>
    <div id='qq'></div>
    <script type="text/html" id="tpl-user">
        <h1>{{cipher}}</h1>
        {{if flag===1}}
           7788
            {{/if}}
            <br>
        //循环输出
        {{each qi}}
        {{$index}}{{$value}}
        {{/each}}
        <h3>{{regTime | dateFormat}}</h3>
    </script>

    <script>
        template.defaults.imports.dateFormat = function (date) {
            var y = date.getFullYear()
            var m = date.getMonth() + 1
            var d = date.getDate()

            return y + '-' + m + '-' + d
        }
        var data = { cipher: '小鸡炖蘑菇', flag: 1, qi: ['七', '八', '九'], regTime: new Date() }
        var str = template('tpl-user', data,)
        console.log(str);

        $('#qq').html(str)
    </script>

</body>

</html>